package cn.javase.io_model.nio._02_Channel;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.junit.jupiter.api.Test;

public class _通道相关的API {

    @Test
    public void test() {
        try(FileOutputStream fos = new FileOutputStream("1.txt");) {
            FileChannel channel = fos.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(1024);
            buffer.put("Hello World世界~".getBytes());
            buffer.flip();
            channel.write(buffer);
            System.out.println("写数据到文件中！");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}
